package com.qfmy.controller.novel;

import com.qfmy.service.novel.NovelSelfService;
import com.qfmy.vo.novel.NovelSelfVo;
import common.result.Result;
import jakarta.annotation.Resource;
import model.annotation.RedisLimitAnnotation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.controller.novel
 * @date 2025/6/7
 * @description 书架
 */
@RestController
@SuppressWarnings("all")
@RequestMapping("/app/novelSelf")
public class NovelSelfController {

    /**
     * 注入service
     */
    @Resource
    private NovelSelfService novelSelfService;

    /**
     * 分页获取书架里面的小说
     */
    @RequestMapping("/getNovelSelf")
    public Result<List<NovelSelfVo>> getNovelSelf(@RequestParam Integer pageNum, @RequestParam Integer size) {
        List<NovelSelfVo> novelSelfs = novelSelfService.getNovelSelf(pageNum, size);
        return Result.ok(novelSelfs);
    }

    /**
     * 加入书架
     */
    @RequestMapping("/addNovelSelf")
    @RedisLimitAnnotation(key = "addNovelSelf", limit = 5, time = 10)
    public Result addNovelSelf(@RequestParam Long novelId) {
        novelSelfService.addNovelSelf(novelId);
        return Result.ok();
    }

    /**
     * 删除书架
     */
    @RequestMapping("/deleteNovelSelf")
    @RedisLimitAnnotation(key = "deleteNovelSelf", limit = 5, time = 10)
    public Result deleteNovelSelf(@RequestParam Long novelId) {
        novelSelfService.deleteNovelSelf(novelId);
        return Result.ok();
    }


}
